import { Location } from '@angular/common'
import { QlMessageService } from 'qloud-angular/package/message/message.service'
import { Router } from '@angular/router'
import { EchartService } from '@shared/utils/echart.service'
import { Component, OnInit, Output, EventEmitter, ViewChild, ViewContainerRef } from '@angular/core'
import { FormGroup, FormBuilder } from '@angular/forms'
import { ModalService } from '@app/shared/utils'
import { ModalConfirmComponent } from '@app/shared/components/modal-confirm/modal-confirm.component'
import { NetService, PageService } from '@app/core/http'
import { ApiService } from '../../services/api.service'
import { CursorService } from '@app/core/http/cursor.service'
import { Store } from '@ngxs/store'



@Component({
  selector: 'app-finanical-config',
  templateUrl: './finanical-config.component.html',
  styleUrls: ['./finanical-config.component.scss'],
  providers: [ModalService, PageService]
})
export class FinanicalConfigComponent implements OnInit {
  public assetsList = []
  public queryAssetparam:any = ''
  public formGroup: FormGroup

  // public formGroup: FormGroup = this.fb.group({
    // customerName: ['张三'],
    // riskLevel: [1],
    // assumption: this.fb.group({ start: [''], end: [''] })
  // })


  public assetConfigure
  public assetslength
  public managerWealth
  public pdfSrc= 'assets/pdf/finanical-plan.pdf';
  constructor(
    public cursorService: CursorService,
    public location: Location,
    private apiService: ApiService,
    private fb: FormBuilder,
    public modal: ModalService,
    public pageService: PageService,
    private message: QlMessageService,
    private echartService: EchartService,
    private router: Router
  ) {
    this.formGroup = fb.group({
      riskLevelCode: [null],
      profitFloor:[null],
      profitCeiling:[null]
  })
}

  ngOnInit() {}

  public onRefresh() {
    // this.getCustomerViewData()
    // this.cursorService.limit = 100
    const queryPaeams = {
      index:0,
      size: 10,
      condition:{
        profitFloor:this.formGroup.value.profitFloor,
        profitCeiling:this.formGroup.value.profitCeiling,
        riskLevelCode:this.formGroup.value.riskLevelCode
      }
    }
    console.log(queryPaeams)
    this.getasstesList(queryPaeams)
  }

  public getasstesList(queryPaeams){
    this.apiService.getAssetList(queryPaeams).subscribe(data=> {
      this.assetslength = data.length
      this.assetsList = data
    })
  }

  public queryAssets(ref:any){
    this.apiService.queryAsset(ref.rowData.assetConfigId).subscribe(data=> {
      const newdata = data.custAssetTypes.map(x=>{
        return{
          value: x.assetOccupyRatio,
          name: x.assetTypeName
        }
      })
      this.assetConfigure = this.echartService.getOption({ type: 'pie', data: newdata })
    })
  }
  // public getCustomerViewData() {
    // this.apiService.getAssetConfigure().subscribe(({ assetPartition, manageWhealth }) => {
      // this.getTradeAssetOption(tradeAsset)
      // this.getTradeEventOption(tradeEvent)
      // this.managerWealth = manageWhealth
      // this.assetConfigure = this.echartService.getOption({ type: 'pie', data: assetPartition })
    // })
  // }
}
